using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Universe.Threading
{
    [Serializable]
    public class InvocationException<T>: Exception, ISerializable
    {
        private readonly int _index;
        private readonly T _element;

        public InvocationException(string message, Exception innerException, int index, T element) : base(message, innerException)
        {
            _index = index;
            _element = element;
        }

        protected InvocationException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            _index = info.GetInt32("index");
            object raw = info.GetValue("element", typeof (T));
            _element = raw == null ? default(T) : (T) raw;
        }


        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("index", _index);
            info.AddValue("element", _element);
        }

        public int Index
        {
            get { return _index; }
        }

        public T Element
        {
            get { return _element; }
        }
    }
}
